package com.styles.codingstyle.utils;

import com.styles.codingstyle.VO.CommonVO;
import com.styles.codingstyle.enums.RESPONSE_ENUM;

/**
 * @author chenjian
 * @Package
 * @Description:通用返回数据结构工具类
 * @date 2018/5/23 10:57
 */
public class CommonVO_Utils {

    public static CommonVO success() {
        CommonVO commonVO = new CommonVO();
        commonVO.setCode(RESPONSE_ENUM.SUCCESS_200.getCode());
        commonVO.setMessage(RESPONSE_ENUM.SUCCESS_200.getMessage());
        commonVO.setData(null);
        return commonVO;
    }

    public static CommonVO success(Object data) {
        CommonVO commonVO = success();
        commonVO.setData(data);
        return commonVO;
    }

    public static CommonVO success(String message) {
        CommonVO commonVO = success();
        commonVO.setMessage(message);
        return commonVO;
    }

    public static CommonVO success(String message, Object data) {
        CommonVO commonVO = success();
        commonVO.setMessage(message);
        commonVO.setData(data);
        return commonVO;
    }

    public static CommonVO success(CommonVO commonVO, String message, Object data) {
        commonVO.setCode(RESPONSE_ENUM.SUCCESS_200.getCode());
        if (null != message) {
            commonVO.setMessage(message);
        } else {
            commonVO.setMessage(RESPONSE_ENUM.SUCCESS_200.getMessage());
        }
        commonVO.setData(data);
        return commonVO;
    }


    public static CommonVO fail(Integer code, String message) {
        CommonVO commonVO = new CommonVO();
        commonVO.setCode(code);
        commonVO.setMessage(message);
        return commonVO;
    }

    public static CommonVO fail_404() {
        CommonVO commonVO = new CommonVO();

        commonVO.setCode(RESPONSE_ENUM.FAIL_404.getCode());
        commonVO.setMessage(RESPONSE_ENUM.FAIL_404.getMessage());
        commonVO.setData(null);
        return commonVO;
    }

    public static CommonVO fail_404(Integer code, String message, Object data) {
        CommonVO commonVO = fail_404();
        commonVO.setData(data);
        commonVO.setCode(code);
        if (null != message) {
            commonVO.setMessage(message);
        }
        return commonVO;
    }

    public static CommonVO fail_404(String message) {
        CommonVO commonVO = fail_404();
        if (null != message) {
            commonVO.setMessage(message);
        }
        return commonVO;
    }

    public static CommonVO fail_404(String message, Object data) {
        CommonVO commonVO = fail_404();
        if (null != message) {
            commonVO.setMessage(message);
        }
        commonVO.setData(data);
        return commonVO;
    }

    public static CommonVO fail_500() {
        CommonVO commonVO = new CommonVO();

        commonVO.setCode(RESPONSE_ENUM.FAIL_500.getCode());
        commonVO.setMessage(RESPONSE_ENUM.FAIL_500.getMessage());
        commonVO.setData(null);
        return commonVO;
    }

    public static CommonVO fail_500(Integer code, String message, Object data) {
        CommonVO commonVO = fail_500();
        commonVO.setData(data);
        commonVO.setCode(code);
        if (null != message) {
            commonVO.setMessage(message);
        }
        return commonVO;
    }

    public static CommonVO fail_500(String message) {
        CommonVO commonVO = fail_500();
        if (null != message) {
            commonVO.setMessage(message);
        }
        return commonVO;
    }

    public static CommonVO fail_500(String message, Object data) {
        CommonVO commonVO = fail_500();
        if (null != message) {
            commonVO.setMessage(message);
        }
        commonVO.setData(data);
        return commonVO;
    }
}
